/*
 
  Copyright (c) 2010, Cristian Costantini - cristian@millemultimedia.it
  
  FileManager is licensed under the terms of the Open Source GPL 3.0 license. 
	
	http://www.gnu.org/licenses/gpl.html
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/


fileManager.ui.DirectoryFormPanel = function(){
	
	var msg = function(title, msg){
        Ext.Msg.show({
            title: title, 
            msg: msg,
            minWidth: 200,
            modal: true,
            icon: Ext.Msg.INFO,
            buttons: Ext.Msg.OK
        });
    };
	
	this.inputPath = new Ext.form.TextField({
		id:'directoryPath',
		name:'directoryPath',
		fieldLabel:'Path',
		width:200,
		allowBlank:false,
		hidden:true,
		hideLabel:true
	});
	
	this.inputName = new Ext.form.TextField({
		id:'directoryName',
		name:'directoryName',
		fieldLabel:'Name',
		width:180,
		allowBlank:false
	});
	
	var panel = new Ext.form.FormPanel({
		
		title:'Create directory',
		frame:true,
		height:110,
		labelWidth:50,
		method:'post',
        bodyStyle: 'padding: 10px 10px 0 10px;',
		items:[
			this.inputPath,
			this.inputName
		],
		buttons:[
			{
				text: 'Reset',
				handler: function(){
					panel.getForm().reset();
				}
			},
        	{text:"Create",
				handler: function(){
					var dirPath=panel.getForm().findField("directoryPath").getValue();
					var newDir=panel.getForm().findField("directoryName").getValue();
					dirNameChk=newDir.trim();
					if (dirPath != "") {  	// check destination dir
						if (dirNameChk != "") {		//check empty dir name
						
							var createDirWait = Ext.MessageBox.wait('Create directory...');
							
							dirPath = dirPath + "/" + newDir;
							//alert(dirPath);
							Ext.Ajax.request({
								url: services.filemanager.createDirectory,
								method: 'post',
								params: {
									directoryPath: "/" + dirPath
								},
								success: function(result,request){
									var jsonResponse = Ext.util.JSON.decode(result.responseText);
									if(jsonResponse.success == true){
										var createDirSuccess = Ext.Msg.alert('Success', 'Directory created on the server');
							
										var log1 = document.getElementById("logArea").value;
										document.getElementById("logArea").value = getCurrentTime() + ' | Directory ' + newDir + ' created\n' + log1;
									}else{
										errorLogHandler(jsonResponse);
									}
								}
							});
							
							panel.getForm().submit({
								url: services.filemanager.createDirectory
							});
							
						}
						else {
							Ext.Msg.show({
								title: 'Error',
								msg: 'Invalid directory name',
								buttons: Ext.Msg.OK,
								maxWidth:300,
								minWidth:300
							});
						}
					}else{
						Ext.Msg.show({
							title: 'Error',
							msg: 'Select the destination directory',
							buttons: Ext.Msg.OK,
							maxWidth:300,
							minWidth:300
						});
					}
				}}
		]
		
	})
	
	return panel;
	
}
/**
 * RGFyaW91cw==
 */